function emphasise(obj) 
{
	var parent = $("#"+obj.id).parent();
	parent.children().removeClass("selected");
		
	$("#"+obj.id).addClass("selected");	
}


function switchView(obj)
{
	// alert(obj.id);
	$("#content-body").removeClass("list-view");
	$("#content-body").removeClass("thumb-view");
	
	if(obj.id == 'button-thumb')
	{
		//alert('Button Thumb-View ist ausgewählt');
		$("#content-body").addClass("thumb-view");
	}
	else 
	{
		//alert('Button List-View ist ausgewählt');
		$("#content-body").addClass("list-view");
	}
}


function expand(obj) 
{	
	// var root = $("#content-body");
	// root.data("test", { first: 16, last: "pizza!" });
	// var parent = $("#"+obj.id).parent();
	// console.log(root.data("test").first);
	
	var children = $(obj).children(); 
	// children.css("border", "3px double red");
	// var len = children.length;
	// console.log("# children: " + len);
	
	
	children.each(function( index ) {
		// console.log(index + " is image element: " + $(this).is("img") );
		
		if ( $(this).is("img") )
		{			
			var parent = $(this).parent().parent();
			
			if ($(this).data("opened") == "true")
				_close($(this), parent);	
			else 
			{
				var old_img_path = $(this).attr("src");
				var new_img_path = "images/content/arrow_expanded.png";		// opened image
				
				$(this).attr("src", new_img_path);
				$(this).data("opened", "true");
				
				console.log(arguments.callee.name + ": change " + old_img_path + " to " + new_img_path );
				console.log(arguments.callee.name + ": opened = " + $(this).data("opened"));
				
				// add comments..
				var parent_id = parent.attr("id");
				parent.append("<div id='comment-"+parent_id+"' class='comments'>loading..</div>");
			
				// load comments..
				var numRand = Math.floor(Math.random()*2) + 1;		
				console.log(numRand);
				// $("#comment-"+parent_id).load("comments.html #section"+parent_id+"");
				// $("#comment-"+parent_id).load("comments.html #c1,#c2,#c3");
				$("#comment-"+parent_id).load("comments.html #section"+numRand+"");

				// for (var i = 0; i < numRand; i++) 
				// {
				// 					
				// }

			}
		}
	});	
}


function _close(obj, parent)
{
	var curr_img_path = $(obj).attr("src");
	var img_closed = "images/content/arrow.png";	// closed image
	
	$(obj).attr("src", img_closed);
	obj.data("opened", "false");
	
	console.log(arguments.callee.name + ": opened = " + obj.data("opened"));
	console.log(arguments.callee.name + ": change " + curr_img_path + " to " + img_closed);
	
	
	var parent_id = parent.attr("id");
	$('#comment-'+parent_id).remove();
	// $('#comment-').remove('.comments');
}
